<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::get('doc', 'Api\SwaggerController@doc');

//Route::get('register', function () {
//    $user = new App\Models\User();
//    $user->name = "tester";
//    $user->email = "test@test.com";
//    $user->password = \Illuminate\Support\Facades\Hash::make("password");
//    $user->save();
//});

Route::post('oauth/token', '\Laravel\Passport\Http\Controllers\AccessTokenController@issueToken');
Route::post('user/register', 'Auth\RegisterController@register');

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {

    $api->resource('extend', 'ExtendController', ['only' => ['index']]);

    $api->resource('template', 'TemplateController', ['only' => ['index', 'show']]);

    $api->group(['middleware' => 'api:auth'], function ($api) {
        $api->get('user/info', 'UserController@getInfo');

        $api->delete('image', 'ImageController@destroy');
        $api->get('image/public', 'ImageController@public_images');
        $api->resource('image', 'ImageController', ['only' => ['index', 'store']]);

        $api->delete('audio', 'AudioController@destroy');
        $api->get('audio/public', 'AudioController@public_audios');
        $api->resource('audio', 'AudioController', ['only' => ['index', 'store']]);


        $api->post('play/update_play', 'PlayController@update_play');
        $api->post('play/destroy_play', 'PlayController@destroy_play');
        $api->resource('play', 'PlayController', ['except' => ['create', 'edit', 'update', 'destroy']]);

        $api->resource('draft', 'DraftController', ['only' => ['index', 'store']]);

        $api->resource('form', 'FromController', ['only' => ['store']]);
    });
});
